<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    h3 {
        height: 500px;
    }
</style>

<body>
    <h3>hhha</h3>
    <h3>hhha</h3>
    <h3>hhha</h3>
    <h3>hhha</h3>
    <h3>hhha</h3>
    <h3>hhha</h3>
    <h3>hhha</h3>

    <script>
        function throttle(func, wait) {
            if (typeof func !== 'function') {
                throw new TypeError('Expected a function');
            }
            if (typeof wait !== 'number' || wait < 0) {
                throw new RangeError('Expected a non-negative number');
            }

            let timeout = null;

            return function (...args) {
                if (timeout === null) {
                    timeout = setTimeout(() => {
                        func.apply(this, args);
                        timeout = null;
                    }, wait);
                }
            };
        }


        window.onscroll = throttle(scrollHandler, 1000)

        function scrollHandler() {
            var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            console.log(scrollTop);
        }

    </script>
</body>

</html>